<?php
/**
 * Created by PhpStorm.
 * User: BlueIdeaLirui
 * Date: 2019/09/03
 * Time: 14:58
 */

namespace business\datacenter\repositories;

use business\company\models\SupplierBasicModel;
use business\company\models\SupplierServiceCategoryModel;
use yii\db\Query;

class SupplierServiceCategoryRepository
{
    /**
     * 通过供应商ID获取供应商服务分类列表
     * @param string $supplierId
     * @param string $fields
     * @return array
     * @throws \yii\db\Exception
     */
    public function getSupplierServiceCategoryListBySupplierId
    (
        $supplierId = '',
        $fields = 'a.supplier_id, b.category_code, c.category_name'
    ) {
        if (!empty($supplierId)) {
            return (new Query())
                ->from(SupplierBasicModel::tableName() . ' a')
                ->select($fields)
                ->innerJoin(SupplierServiceCategoryModel::tableName() . ' b', 'a.supplier_id = b.supplier_id')
                ->innerJoin('b2b_parameter.bsp_basic_forest c', 'b.category_code = c.category_code')
                ->where(['a.supplier_id' => $supplierId, 'a.status' => 2, 'a.state' => 2])
                ->andWhere(['NOT LIKE', 'a.company_name', 'test'])
                ->createCommand(SupplierServiceCategoryModel::getDb())
                ->queryAll();
        }

        return [];
    }
}
